<template>
    <div>
       <el-form ref="form" :model="form"  label-width="125px">
           <el-row v-for="col in columns" :key="col.label">

               <el-col :span="col.span" v-if="col.type=='radio'">
                   <el-form-item :label="col.label" :prop="col.prop">
                       <el-radio v-for="dic in col.dicData" :key="dic.label" v-model="form[col.label]" :label="dic.label"></el-radio>
                   </el-form-item>
               </el-col>

               <el-col :span="col.span" v-else>
                   <el-form-item :label="col.label" :prop="col.prop">
                       <el-input  v-model="form[col.label]" :placeholder="col.formTips"></el-input>
                   </el-form-item>
               </el-col>

           </el-row>
       </el-form>
       <el-row type="flex" justify="end">
            <el-col :span="12">
                <el-button type="primary" @click="submitForm">{{operateBtnName}}</el-button>
                <el-button @click="cancel">取 消</el-button>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import {addConsumerCredential} from '@/api/kong/consumer.js';
export default {
    props: {
        consumerId:{
            type: String,
            required:false,
        },
        columns:{
            type: Array,
            required:false,
        },
        cerdential:{
            type: Object,
            required: false
        },
        form:{
            type: Object,
            required: false,
        }
    },
    data () {
        return {
            operateBtnName: '添加'
        }
    },
    created(){
        console.log("this.form:",this.form,"this.columns",this.columns,"this.cerdential",this.cerdential)
    },
    methods:{
        submitForm(){
            // console.log(JSON.stringify(this.form));
            addConsumerCredential(this.consumerId,this.cerdential.value,this.form).then(res =>{
                console.log(JSON.stringify(res));
                this.$emit('callback',"新增成功");
            })
        },
        cancel(){

        },
        currentFormId(label){
            return "form."+label;
        }
    }
}
</script>